package com.myway.service.impl;

import com.myway.dao.FlyOrderMapper;
import com.myway.dao.FlyOrderPaymentMapper;
import com.myway.dao.PaymentMapper;
import com.myway.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by qianmi-05 on 2018/8/17.
 */
@Service
public class PaymentServiceImpl implements PaymentService{

    @Autowired
    private PaymentMapper paymentMapper;

    @Autowired
    private FlyOrderMapper flyOrderMapper;

    @Autowired
    private FlyOrderPaymentMapper flyOrderPaymentMapper;



   /* public int addPaymentInfo(Payment payment,String payType) {
        if(payment==null){
            return -1;
        }
        payment.setPayType(payType);
        return paymentMapper.insertSelective(payment);
    }

    @Override
    @Transactional
    public int addPaymentInfo(String payment_id, String order_number, String order_currency, String order_amount, String methods,String card_number,String order_notes,String payment_status) {
        FlyOrder flyOrder = flyOrderMapper.selectFlyOrderByOrderId(order_number);
        if(flyOrder==null){
            return  -1;
        }
        Payment payment=new Payment();
        payment.setPaymentNo(payment_id);
        payment.setPayType("OCEANPAY");
        payment.setAction("pay");//机票支付
        payment.setAmount(new BigDecimal(order_amount));
        payment.setPayTime(new Date());
        payment.setCurrency(order_currency);
        payment.setPayer(flyOrder.getContactName());
        payment.setRemark(order_notes);
        payment.setMerchantId("140105");
        payment.setBankId(card_number);
        if(payment_status.equals("1")){
            payment.setPayStatus("PAID");
        }else{
            payment.setPayStatus("FAIL");
        }
        int paymentNum = paymentMapper.insertSelective(payment);
        if(paymentNum>0){
            FlyOrderPayment flyOrderPayment=new FlyOrderPayment();
            flyOrderPayment.setPaymentId(payment.getId().intValue());
            flyOrderPayment.setAmount(new BigDecimal(order_amount));
            flyOrderPayment.setOrderNo(flyOrder.getId()+"");
            int insertSelective = flyOrderPaymentMapper.insertSelective(flyOrderPayment);
            if(insertSelective<0){
                return  -1;
            }
        }else{
            return -1;
        }
       return 1;
    }

    @Override
    public int addOrderPaymentInfo(FlyOrderPayment flyOrderPayment) {
        if(flyOrderPayment==null){
            return -1;
        }
        return flyOrderPaymentMapper.insertSelective(flyOrderPayment);
    }*/
}
